package fr.alma.domo.svc;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.oasisopen.sca.annotation.AllowsPassByReference;
import org.oasisopen.sca.annotation.Service;

import fr.alma.domo.model.AbstractService;
import fr.alma.domo.model.Context;
import fr.alma.domo.util.Log;

/**
 * Gere l'ensemble des Contexts
 */
@SuppressWarnings("serial")
@Service(ContextHandler.class)
@AllowsPassByReference
public class ContextHandlerImpl extends AbstractService implements ContextHandler {
	
	public ContextHandlerImpl() {
		super("ContextHandler");
	}

	private static final Map<String,Context> contexts = new HashMap<String,Context>();

	@Override
	public void addContext(Context c) {
		if(c!=null){
			Log.i(getClass().getName(), "Registring context [%s]", c.getId());
			contexts.put(c.getId(),c);		
		}
	}
	
	@Override
	public Context getContextById(String contextId){
		return contexts.get(contextId);
	}

	public Map<String,Context> getContexts(){
		return Collections.unmodifiableMap(contexts);
	}
	
}
